﻿@using eCollabro.Client.Models.Content;
@using eCollabro.Client.Models.Core;
@using eCollabro.Common;
@using eCollabro.Web.Base;
@model BlogModel
@if (!Request.IsAjaxRequest())
{
    @Scripts.Render("~/bundles/blog")
}
@{
    List<PermissionEnum> userPermissions = (List<PermissionEnum>)ViewBag.UserPermissions;
    bool canEdit = userPermissions.Contains(PermissionEnum.EditContent);
    bool canDelete = userPermissions.Contains(PermissionEnum.DeleteContent);
    bool canAdd = userPermissions.Contains(PermissionEnum.AddContent);

    List<PageButton> pageButtons = new List<PageButton>();
    pageButtons.Add(new PageButton { Id = "btnBlogs", ButtonText = "Blogs", CssClass = "btn btn-success", Icon = "th-list", Method = "openBlogs(" + Model.BlogCategoryId + ")" });
    if ((canEdit && !Model.BlogId.Equals(0)) || (canAdd && Model.BlogId.Equals(0)))
    {
        pageButtons.Add(new PageButton { Id = "btnSave", ButtonText = "Save", CssClass = "btn btn-primary", Icon = "floppy-disk", Method = "saveBlog()" });
    }
}
<script type="text/javascript">
    $(document).ready(function () {
        $blogContentEditor = $("#BlogContent").cleditor()[0];
        $blogContentEditor.focus();
    });
</script>
<div id="divBlog" ng-controller="manageBlogController" ng-init="loadBlog(@Model.BlogId,@Model.BlogCategoryId)">
    @Html.Partial("_PageHeader", new PageHeaderModel { ViewId = "Blog", PageTitle = "Blog - Add/Edit", ValidateForm = true, PageButtons = pageButtons })
    @using (Html.BeginForm("Blog", "Blog", FormMethod.Post, new { role = "form", id = "frmBlog", @class = "form-horizontal" }))
    {

        @Html.AntiForgeryToken()
        <div class="form-group">
            @Html.LabelFor(m => m.BlogTitle, new { @class = "col-md-2 control-label" })
            <div class="col-md-5">
                @Html.TextBoxFor(m => m.BlogTitle, new { ng_model = "blog.BlogTitle", @class = "form-control", maxlength = "50" })
                @Html.ValidationMessageFor(m => m.BlogTitle)
            </div>
        </div>
        <div class="form-group">
            @Html.LabelFor(m => m.BlogDescription, new { @class = "col-md-2 control-label" })
            <div class="col-md-5">
                @Html.TextAreaFor(m => m.BlogDescription, new { ng_model = "blog.BlogDescription", @class = "form-control", maxlength = "255" })
            </div>
        </div>
        <div class="form-group">
            @Html.LabelFor(m => m.BlogContent, new { @class = "col-md-2 control-label" })
            <div class="col-md-10">
                @Html.TextAreaFor(m => m.BlogContent, new { ng_model = "blog.BlogContent", style = "width: 724px; height: 197px;" })
                @Html.ValidationMessageFor(m => m.BlogContent)
            </div>
        </div>
        <div class="form-group">
            @Html.LabelFor(m => m.BlogCategoryId, new { @class = "col-md-2 control-label" })
            <div class="col-md-5">
                <select data-ng-model="selectedBlogCategory" ng-options="blogCategory.BlogCategoryName for blogCategory in blogCategories" class="form-control" ng-change="updateBlogCategory()"></select>
            </div>
        </div>
        <div class="form-group">
            <div class="col-md-2"></div>
            <div class="col-md-10">
                <div class="checkbox">
                    @Html.CheckBoxFor(m => m.IsActive, new { ng_model = "blog.IsActive" })
                    @Html.LabelFor(m => m.IsActive)
                </div>
            </div>
        </div>
        <div class="col-md-1"></div>
        <div class="col-md-11">
            <div class="panel panel-default">
                <!-- Default panel contents -->
                <div class="panel-heading">Content Setting</div>
                <div class="panel-body">
                    <div class="form-group" style="padding-left:2px">
                        <label class="checkbox-inline">
                            @Html.CheckBoxFor(m => m.IsAnomynousAccess, new { ng_model = "blog.IsAnomynousAccess" }) @Html.LabelFor(m => m.IsAnomynousAccess)
                        </label>
                        <label class="checkbox-inline">
                            @Html.CheckBoxFor(m => m.IsCommentsAllowed, new { ng_model = "blog.IsCommentsAllowed" }) @Html.LabelFor(m => m.IsCommentsAllowed)
                        </label>
                        <label class="checkbox-inline">
                            @Html.CheckBoxFor(m => m.IsLikeAllowed, new { ng_model = "blog.IsLikeAllowed" }) @Html.LabelFor(m => m.IsLikeAllowed)
                        </label>
                        <label class="checkbox-inline">
                            @Html.CheckBoxFor(m => m.IsRatingAllowed, new { ng_model = "blog.IsRatingAllowed" }) @Html.LabelFor(m => m.IsRatingAllowed)
                        </label>
                        <label class="checkbox-inline">
                            @Html.CheckBoxFor(m => m.IsVotingAllowed, new { ng_model = "blog.IsVotingAllowed" }) @Html.LabelFor(m => m.IsVotingAllowed)
                        </label>
                    </div>
                </div>
            </div>
        </div>
        <div class="col-md-12">
            @Html.Partial("_PageFooter", new PageFooterModel
                {
                    PageButtons = pageButtons
                })
        </div>
    }
</div>
